﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using Spaanjaars.ContactManager.Infrastructure.UnitOfWork;
using Spaanjaars.ContactManager.Model;
using Spaanjaars.ContactManager.Services.Commands;
using Spaanjaars.ContactManager.Services.Implementations;
using Spaanjaars.ContactManager.Services.Interfaces;

namespace Spaanjaars.ContactManager.Tests.Service
{
    [TestFixture]
    public class When_submitting_an_invalid_command_to_create_a_contact_person
    {
        private IContactPersonRepository _contactPersonRepository;
        private IUnitOfWork _uow;
        private CreateContactPersonCommandResult _response;

        [SetUp]
        public void Context()
        {
            var mocks = new MockRepository();

            _contactPersonRepository = mocks.Stub<IContactPersonRepository>();           
            _uow = mocks.Stub<IUnitOfWork>();            
        }

        [Test]
        public void The_response_should_contain_a_list_of_broken_rules()
        {
            IContactPersonCreationService contactPersonCreationService = new ContactPersonCreationService(_contactPersonRepository, _uow);

            var contactPerson = new CreateContactPersonCommand()
            {
                FirstName = string.Empty,
                MiddleName = string.Empty,
                LastName = "Millett",
                DateOfBirth = DateTime.Now
            };            

            _response = contactPersonCreationService.CreatePersonFrom(contactPerson);

            Assert.That(_response.BrokenRules.Count().Equals(1));

            // Ensure the broken rule matches the missing field
            Assert.Fail();
        }      
    }
}
